package com.example.mymatch.controller;

import com.example.mymatch.model.Ppy;
import com.example.mymatch.service.IPpyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "物业人员")
@RestController
public class PpyController {
    @Autowired
    private IPpyService ppyService;//对某个业务服务的内容进行定义规范  编写者：谢楷诗
    @ApiOperation(value = "查询所有物业人员信息",notes = "获取物业人员信息返回json字符串")
    @RequestMapping("/getStr24")
    public String getPpy(){return "My ppy";}
    @CrossOrigin
    @ApiOperation(value = "对物业人员信息的添加方法")
    @GetMapping("/addPpy")
    public int addPpy(Ppy ppy){
        System.out.println("进入添加物业人员信息接口");
        return ppyService.insertPpy(ppy);
    }

    @GetMapping("getAll24")
    @ApiOperation(value = "对物业人员信息查询方法")
    public List<Ppy> getAllPpy(Ppy ppy){
        System.out.println("进入查询方法");
        List<Ppy> listPpy=ppyService.getAllPpy(ppy);
        return listPpy;
    }
    @PutMapping("/editPpy")
    @ApiOperation(value = "对物业人员信息的修改方法")
    public int EditPpy(@RequestBody Ppy ppy){
        System.out.println("进入物业人员修改方法");
        return ppyService.updatePpy(ppy);
    }
    @GetMapping("/delPpy")
    @ApiOperation(value = "对物业人员信息的删除方法")
    public int Delete(int id){
        System.out.println("进入物业人员删除方法");
        int returnValue=0;
        if (id!=0){
            Ppy ppy=new Ppy();
            ppy.setPpyId(id);
            returnValue= ppyService.deletePpy(ppy);
        }
        return returnValue;
    }
    @GetMapping("/getOne24")
    @ApiOperation(value = "对单条物业人员信息的查询方法")
    public Ppy getPpy(int id){
        Ppy ppy=new Ppy();
        System.out.println("进入单条查询方法");
        if (id!=0){
            Ppy ppy1=new Ppy();
            ppy1.setPpyId(id);
            ppy=ppyService.getPpy(ppy1);
            System.out.println("返回的数据集合为："+ppy.getPpyName());
        }
        return ppy;
    }
}

